home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Internet & Communication / WordPress 1.5.1.dmg / wordpress / wp-admin / post.php < prev    next >
Encoding:
PHP Script  |  2005-04-24  |  27.0 KB  |  794 lines

  1. <?php
  2. require_once('admin.php');
  3.  
  4. $wpvarstoreset = array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder' );
  5.  
  6. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  7.     $wpvar = $wpvarstoreset[$i];
  8.     if (!isset($$wpvar)) {
  9.         if (empty($_POST["$wpvar"])) {
  10.             if (empty($_GET["$wpvar"])) {
  11.                 $$wpvar = '';
  12.             } else {
  13.             $$wpvar = $_GET["$wpvar"];
  14.             }
  15.         } else {
  16.             $$wpvar = $_POST["$wpvar"];
  17.         }
  18.     }
  19. }
  20.  
  21. if (isset($_POST['deletepost'])) {
  22. $action = "delete";
  23. }
  24.  
  25.     // Fix submenu highlighting for pages.
  26. if (false !== strpos($_SERVER['HTTP_REFERER'], 'edit-pages.php')) $submenu_file = 'page-new.php';
  27.  
  28. $editing = true;
  29.  
  30. switch($action) {
  31. case 'post':
  32.  
  33.     if ( !user_can_create_draft($user_ID) )
  34.         die( __('You are not allowed to create posts or drafts on this blog.') );
  35.  
  36.     $post_pingback = (int) $_POST['post_pingback'];
  37.     $content         = apply_filters('content_save_pre',  $_POST['content']);
  38.     $excerpt         = apply_filters('excerpt_save_pre',  $_POST['excerpt']);
  39.     $post_title      = apply_filters('title_save_pre',    $_POST['post_title']);
  40.     $post_categories = apply_filters('category_save_pre', $_POST['post_category']);
  41.     $post_status     = apply_filters('status_save_pre',   $_POST['post_status']);
  42.     $post_name       = apply_filters('name_save_pre',     $_POST['post_name']);
  43.     $post_parent = 0;
  44.     $menu_order  = 0;
  45.     
  46.  
  47.     if ( isset($_POST['parent_id']) )
  48.         $post_parent = (int) $_POST['parent_id'];
  49.  
  50.     if ( isset($_POST['menu_order']) )
  51.         $menu_order = (int) $_POST['menu_order'];
  52.  
  53.     if (! empty($_POST['post_author_override'])) {
  54.         $post_author = (int) $_POST['post_author_override'];
  55.     } else if (! empty($_POST['post_author'])) {
  56.         $post_author = (int) $_POST['post_author'];
  57.     } else {
  58.         $post_author = (int) $_POST['user_ID'];
  59.     }
  60.     if ( !user_can_edit_user($user_ID, $post_author) )
  61.         die( __('You cannot post as this user.') );
  62.  
  63.     if ( empty($post_status) )
  64.         $post_status = 'draft';
  65.     // Double-check
  66.     if ( 'publish' == $post_status && (!user_can_create_post($user_ID)) )
  67.         $post_status = 'draft';
  68.         
  69.     $comment_status = $_POST['comment_status'];
  70.     if ( empty($comment_status) ) {
  71.         if ( !isset($_POST['advanced_view']) )
  72.             $comment_status = get_option('default_comment_status');
  73.         else
  74.             $comment_status = 'closed';
  75.         }
  76.  
  77.     $ping_status = $_POST['ping_status'];
  78.     if ( empty($ping_status) ) {
  79.         if ( !isset($_POST['advanced_view']) )
  80.             $ping_status = get_option('default_ping_status');            
  81.         else
  82.             $ping_status = 'closed';
  83.         }
  84.  
  85.     $post_password = $_POST['post_password'];
  86.     
  87.     $trackback = $_POST['trackback_url'];
  88.     $trackback = preg_replace('|\s+|', "\n", $trackback);
  89.  
  90.     if (user_can_set_post_date($user_ID) && (!empty($_POST['edit_date']))) {
  91.         $aa = $_POST['aa'];
  92.         $mm = $_POST['mm'];
  93.         $jj = $_POST['jj'];
  94.         $hh = $_POST['hh'];
  95.         $mn = $_POST['mn'];
  96.         $ss = $_POST['ss'];
  97.         $jj = ($jj > 31) ? 31 : $jj;
  98.         $hh = ($hh > 23) ? $hh - 24 : $hh;
  99.         $mn = ($mn > 59) ? $mn - 60 : $mn;
  100.         $ss = ($ss > 59) ? $ss - 60 : $ss;
  101.         $now = "$aa-$mm-$jj $hh:$mn:$ss";
  102.         $now_gmt = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss");
  103.     } else {
  104.         $now = current_time('mysql');
  105.         $now_gmt = current_time('mysql', 1);
  106.     }
  107.  
  108.     // What to do based on which button they pressed
  109.     if ('' != $_POST['saveasdraft']) $post_status = 'draft';
  110.     if ('' != $_POST['saveasprivate']) $post_status = 'private';
  111.     if ('' != $_POST['publish']) $post_status = 'publish';
  112.     if ('' != $_POST['advanced']) $post_status = 'draft';
  113.     if ('' != $_POST['savepage']) $post_status = 'static';
  114.  
  115.  
  116.  
  117.     $id_result = $wpdb->get_row("SHOW TABLE STATUS LIKE '$wpdb->posts'");
  118.     $post_ID = $id_result->Auto_increment;
  119.  
  120.     if ( empty($post_name) ) {
  121.         if ( 'draft' != $post_status )
  122.             $post_name = sanitize_title($post_title, $post_ID);
  123.     } else {
  124.         $post_name = sanitize_title($post_name, $post_ID);
  125.     }
  126.  
  127.     if ('publish' == $post_status) {
  128.         $post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
  129.         if ($post_name_check) {
  130.             $suffix = 2;
  131.             while ($post_name_check) {
  132.                 $alt_post_name = $post_name . "-$suffix";
  133.                 $post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
  134.                 $suffix++;
  135.             }
  136.             $post_name = $alt_post_name;
  137.         }
  138.     }
  139.  
  140.     $postquery ="INSERT INTO $wpdb->posts
  141.             (ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt,  post_status, comment_status, ping_status, post_password, post_name, to_ping, post_modified, post_modified_gmt, post_parent, menu_order)
  142.             VALUES
  143.             ('$post_ID', '$post_author', '$now', '$now_gmt', '$content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$trackback', '$now', '$now_gmt', '$post_parent', '$menu_order')
  144.             ";
  145.  
  146.     $result = $wpdb->query($postquery);
  147.  
  148.     if (!empty($_POST['mode'])) {
  149.     switch($_POST['mode']) {
  150.         case 'bookmarklet':
  151.             $location = 'bookmarklet.php?a=b';
  152.             break;
  153.         case 'sidebar':
  154.             $location = 'sidebar.php?a=b';
  155.             break;
  156.         default:
  157.             $location = 'post.php';
  158.             break;
  159.         }
  160.     } else {
  161.         $location = 'post.php?posted=true';
  162.     }
  163.  
  164.     if ( 'static' == $_POST['post_status'] )
  165.         $location = "page-new.php?saved=true";
  166.  
  167.     if ( '' != $_POST['advanced'] || isset($_POST['save']) )
  168.         $location = "post.php?action=edit&post=$post_ID";
  169.  
  170.     header("Location: $location"); // Send user on their way while we keep working
  171.  
  172.     // Insert categories
  173.     // Check to make sure there is a category, if not just set it to some default
  174.     if (!$post_categories) $post_categories[] = get_option('default_category');
  175.     foreach ($post_categories as $post_category) {
  176.         // Double check it's not there already
  177.         $exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_ID AND category_id = $post_category");
  178.  
  179.          if (!$exists) { 
  180.             $wpdb->query("
  181.             INSERT INTO $wpdb->post2cat
  182.             (post_id, category_id)
  183.             VALUES
  184.             ($post_ID, $post_category)
  185.             ");
  186.         }
  187.     }
  188.  
  189.     add_meta($post_ID);
  190.  
  191.     $wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
  192.  
  193.     do_action('save_post', $post_ID);
  194.  
  195.     if ('publish' == $post_status) {
  196.         if ($post_pingback)
  197.             pingback($content, $post_ID);
  198.         do_enclose( $content, $post_ID );
  199.         do_trackbacks($post_ID);
  200.         do_action('publish_post', $post_ID);
  201.     }
  202.  
  203.     if ($post_status == 'static') {
  204.         generate_page_rewrite_rules();
  205.         add_post_meta($post_ID, '_wp_page_template',  $_POST['page_template'], true);
  206.     }
  207.  
  208.     require_once('admin-header.php');
  209.  
  210.     exit();
  211.     break;
  212.  
  213. case 'edit':
  214.     $title = __('Edit');
  215.  
  216.     require_once('admin-header.php');
  217.  
  218.     $post = $post_ID = $p = (int) $_GET['post'];
  219.  
  220.     if ( !user_can_edit_post($user_ID, $post_ID) )
  221.         die ( __('You are not allowed to edit this post.') );
  222.         
  223.     $postdata = &get_post($post_ID);
  224.     $content = $postdata->post_content;
  225.     $content = format_to_edit($content);
  226.     $content = apply_filters('content_edit_pre', $content);
  227.     $excerpt = $postdata->post_excerpt;
  228.     $excerpt = format_to_edit($excerpt);
  229.     $excerpt = apply_filters('excerpt_edit_pre', $excerpt);
  230.     $edited_post_title = format_to_edit($postdata->post_title);
  231.     $edited_post_title = apply_filters('title_edit_pre', $edited_post_title);
  232.     $post_status = $postdata->post_status;
  233.     $comment_status = $postdata->comment_status;
  234.     $ping_status = $postdata->ping_status;
  235.     $post_password = $postdata->post_password;
  236.     $to_ping = $postdata->to_ping;
  237.     $pinged = $postdata->pinged;
  238.     $post_name = $postdata->post_name;
  239.     $post_parent = $postdata->post_parent;
  240.     $post_author = $postdata->post_author;
  241.     $menu_order = $postdata->menu_order;
  242.  
  243.     if( 'private' == $postdata->post_status && $postdata->post_author != $user_ID )
  244.         die ( __('You are not allowed to view other users\' private posts.') );
  245.  
  246.     if ($post_status == 'static') {
  247.         $page_template = get_post_meta($post_ID, '_wp_page_template', true);
  248.         include('edit-page-form.php');
  249.     } else {
  250.         include('edit-form-advanced.php');
  251.     }
  252.  
  253.     $post = &$postdata;
  254.     ?>
  255.     <div id='preview' class='wrap'>
  256.     <h2><?php _e('Post Preview (updated when post is saved)'); ?></h2>
  257.     <h3 class="storytitle" id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__("Permanent Link: %s"), get_the_title()); ?>"><?php the_title(); ?></a></h3>
  258.     <div class="meta"><?php _e("Filed under:"); ?> <?php the_category(','); ?> — <?php the_author() ?> @ <?php the_time() ?></div>
  259.  
  260.     <div class="storycontent">
  261.     <?php 
  262.     $content = apply_filters('the_content', $post->post_content);
  263.     echo $content;
  264.     ?>
  265.     </div>
  266.     </div>
  267.     <?php
  268.     break;
  269.  
  270. case 'editpost':
  271.     // die(var_dump('<pre>', $_POST));
  272.     if (!isset($blog_ID)) {
  273.         $blog_ID = 1;
  274.     }
  275.     $post_ID = $_POST['post_ID'];
  276.  
  277.     if (!user_can_edit_post($user_ID, $post_ID, $blog_ID))
  278.         die( __('You are not allowed to edit this post.') );
  279.  
  280.     $post_categories = $_POST['post_category'];
  281.     if (!$post_categories) $post_categories[] = 1;
  282.     $content = apply_filters('content_save_pre', $_POST['content']);
  283.     $excerpt = apply_filters('excerpt_save_pre', $_POST['excerpt']);
  284.     $post_title = $_POST['post_title'];
  285.     $prev_status = $_POST['prev_status'];
  286.     $post_status = $_POST['post_status'];
  287.     $menu_order = (int) $_POST['menu_order'];
  288.     if (! empty($_POST['post_author_override'])) {
  289.         $post_author = (int) $_POST['post_author_override'];
  290.     } else if (! empty($_POST['post_author'])) {
  291.         $post_author = (int) $_POST['post_author'];
  292.     } else {
  293.         $post_author = (int) $_POST['user_ID'];
  294.     }
  295.     if ( !user_can_edit_user($user_ID, $post_author) )
  296.         die( __('You cannot post as this user.') );
  297.  
  298.     $comment_status = $_POST['comment_status'];
  299.     if (empty($comment_status)) $comment_status = 'closed';
  300.     //if (!$_POST['comment_status']) $comment_status = get_settings('default_comment_status');
  301.  
  302.     $ping_status = $_POST['ping_status'];
  303.     if (empty($ping_status)) $ping_status = 'closed';
  304.     //if (!$_POST['ping_status']) $ping_status = get_settings('default_ping_status');
  305.     $post_password = $_POST['post_password'];
  306.     $post_name = $_POST['post_name'];
  307.  
  308.     $post_parent = 0;
  309.     if (isset($_POST['parent_id'])) {
  310.         $post_parent = $_POST['parent_id'];
  311.     }
  312.  
  313.     $trackback = $_POST['trackback_url'];
  314.     // Format trackbacks
  315.     $trackback = preg_replace('|\s+|', '\n', $trackback);
  316.     
  317.     if (isset($_POST['publish'])) $post_status = 'publish';
  318.     // Double-check
  319.     if ( 'publish' == $post_status && (!user_can_create_post($user_ID)) )
  320.         $post_status = 'draft';
  321.  
  322.     if ( empty($post_name) ) {
  323.         if ( 'draft' != $post_status )
  324.             $post_name = sanitize_title($post_title, $post_ID);
  325.     } else {
  326.         $post_name = sanitize_title($post_name, $post_ID);
  327.     }
  328.  
  329.     if ('publish' == $post_status) {
  330.         $post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
  331.         if ($post_name_check) {
  332.             $suffix = 2;
  333.             while ($post_name_check) {
  334.                 $alt_post_name = $post_name . "-$suffix";
  335.                 $post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
  336.                 $suffix++;
  337.             }
  338.             $post_name = $alt_post_name;
  339.         }
  340.     }
  341.  
  342.     if (user_can_edit_post_date($user_ID, $post_ID) && (!empty($_POST['edit_date']))) {
  343.         $aa = $_POST['aa'];
  344.         $mm = $_POST['mm'];
  345.         $jj = $_POST['jj'];
  346.         $hh = $_POST['hh'];
  347.         $mn = $_POST['mn'];
  348.         $ss = $_POST['ss'];
  349.         $jj = ($jj > 31) ? 31 : $jj;
  350.         $hh = ($hh > 23) ? $hh - 24 : $hh;
  351.         $mn = ($mn > 59) ? $mn - 60 : $mn;
  352.         $ss = ($ss > 59) ? $ss - 60 : $ss;
  353.         $datemodif = ", post_date = '$aa-$mm-$jj $hh:$mn:$ss'";
  354.     $datemodif_gmt = ", post_date_gmt = '".get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss")."'";
  355.     } else {
  356.         $datemodif = '';
  357.         $datemodif_gmt = '';
  358.     }
  359.  
  360.     $now = current_time('mysql');
  361.     $now_gmt = current_time('mysql', 1);
  362.  
  363.     $result = $wpdb->query("
  364.         UPDATE $wpdb->posts SET
  365.             post_content = '$content',
  366.             post_excerpt = '$excerpt',
  367.             post_title = '$post_title'"
  368.             .$datemodif_gmt
  369.             .$datemodif.",            
  370.             post_status = '$post_status',
  371.             comment_status = '$comment_status',
  372.             ping_status = '$ping_status',
  373.             post_author = '$post_author',
  374.             post_password = '$post_password',
  375.             post_name = '$post_name',
  376.             to_ping = '$trackback',
  377.             post_modified = '$now',
  378.             post_modified_gmt = '$now_gmt',
  379.             menu_order = '$menu_order',
  380.             post_parent = '$post_parent'
  381.         WHERE ID = $post_ID ");
  382.  
  383.     if ($_POST['save']) {
  384.         $location = $_SERVER['HTTP_REFERER'];
  385.     } elseif ($_POST['updatemeta']) {
  386.         $location = $_SERVER['HTTP_REFERER'] . '&message=2#postcustom';
  387.     } elseif ($_POST['deletemeta']) {
  388.         $location = $_SERVER['HTTP_REFERER'] . '&message=3#postcustom';
  389.     } elseif (isset($_POST['referredby']) && $_POST['referredby'] != $_SERVER['HTTP_REFERER']) {
  390.         $location = $_POST['referredby'];
  391.         if ( $_POST['referredby'] == 'redo' )
  392.             $location = get_permalink( $post_ID );
  393.     } else {
  394.         $location = 'post.php';
  395.     }
  396.     header ('Location: ' . $location); // Send user on their way while we keep working
  397.  
  398.     // Meta Stuff
  399.     if ($_POST['meta']) :
  400.         foreach ($_POST['meta'] as $key => $value) :
  401.             update_meta($key, $value['key'], $value['value']);
  402.         endforeach;
  403.     endif;
  404.  
  405.     if ($_POST['deletemeta']) :
  406.         foreach ($_POST['deletemeta'] as $key => $value) :
  407.             delete_meta($key);
  408.         endforeach;
  409.     endif;
  410.  
  411.     add_meta($post_ID);
  412.  
  413.     // Now it's category time!
  414.     // First the old categories
  415.     $old_categories = $wpdb->get_col("SELECT category_id FROM $wpdb->post2cat WHERE post_id = $post_ID");
  416.     
  417.     // Delete any?
  418.     foreach ($old_categories as $old_cat) {
  419.         if (!in_array($old_cat, $post_categories)) // If a category was there before but isn't now
  420.             $wpdb->query("DELETE FROM $wpdb->post2cat WHERE category_id = $old_cat AND post_id = $post_ID LIMIT 1");
  421.     }
  422.     
  423.     // Add any?
  424.     foreach ($post_categories as $new_cat) {
  425.         if (!in_array($new_cat, $old_categories))
  426.             $wpdb->query("INSERT INTO $wpdb->post2cat (post_id, category_id) VALUES ($post_ID, $new_cat)");
  427.     }
  428.  
  429.     if ($prev_status != 'publish' && $post_status == 'publish')
  430.         do_action('private_to_published', $post_ID);
  431.  
  432.     if ($post_status == 'publish') {
  433.         do_action('publish_post', $post_ID);
  434.         do_trackbacks($post_ID);
  435.         do_enclose( $content, $post_ID );
  436.         if ( get_option('default_pingback_flag') )
  437.             pingback($content, $post_ID);
  438.     }
  439.  
  440.     if ($post_status == 'static') {
  441.         generate_page_rewrite_rules();
  442.  
  443.         if ( ! update_post_meta($post_ID, '_wp_page_template',  $_POST['page_template'])) {
  444.             add_post_meta($post_ID, '_wp_page_template',  $_POST['page_template'], true);
  445.         }
  446.     }
  447.  
  448.     do_action('edit_post', $post_ID);
  449.     exit();
  450.     break;
  451.  
  452. case 'delete':
  453.     check_admin_referer();
  454.  
  455.     $post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
  456.     
  457.     if (!user_can_delete_post($user_ID, $post_id)) {
  458.         die( __('You are not allowed to delete this post.') );
  459.     }
  460.  
  461.     if (! wp_delete_post($post_id))
  462.         die( __('Error in deleting...') );
  463.  
  464.     $sendback = $_SERVER['HTTP_REFERER'];
  465.     if (strstr($sendback, 'post.php')) $sendback = get_settings('siteurl') .'/wp-admin/post.php';
  466.     $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
  467.     header ('Location: ' . $sendback);
  468.     generate_page_rewrite_rules();
  469.     do_action('delete_post', $post_id);
  470.     break;
  471.  
  472. case 'editcomment':
  473.     $title = __('Edit Comment');
  474.     $parent_file = 'edit.php';
  475.     require_once ('admin-header.php');
  476.  
  477.     get_currentuserinfo();
  478.  
  479.     $comment = $_GET['comment'];
  480.     $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'javascript:history.go(-1)'));
  481.  
  482.     if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
  483.         die( __('You are not allowed to edit comments on this post.') );
  484.     }
  485.  
  486.     $content = $commentdata['comment_content'];
  487.     $content = format_to_edit($content);
  488.     $content = apply_filters('comment_edit_pre', $content);
  489.     
  490.     $comment_status = $commentdata['comment_approved'];
  491.  
  492.     include('edit-form-comment.php');
  493.  
  494.     break;
  495.  
  496. case 'confirmdeletecomment':
  497.  
  498.     require_once('./admin-header.php');
  499.  
  500.     $comment = $_GET['comment'];
  501.     $p = (int) $_GET['p'];
  502.     $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  503.  
  504.     if (!user_can_delete_post_comments($user_ID, $commentdata['comment_post_ID'])) {
  505.         die( __('You are not allowed to delete comments on this post.') );
  506.     }
  507.  
  508.     echo "<div class=\"wrap\">\n";
  509.     echo "<p>" . __('<strong>Caution:</strong> You are about to delete the following comment:') . "</p>\n";
  510.     echo "<table border=\"0\">\n";
  511.     echo "<tr><td>" . __('Author:') . "</td><td>" . $commentdata["comment_author"] . "</td></tr>\n";
  512.     echo "<tr><td>" . __('E-mail:') . "</td><td>" . $commentdata["comment_author_email"] . "</td></tr>\n";
  513.     echo "<tr><td>". __('URL:') . "</td><td>" . $commentdata["comment_author_url"] . "</td></tr>\n";
  514.     echo "<tr><td>". __('Comment:') . "</td><td>" . stripslashes($commentdata["comment_content"]) . "</td></tr>\n";
  515.     echo "</table>\n";
  516.     echo "<p>" . __('Are you sure you want to do that?') . "</p>\n";
  517.  
  518.     echo "<form action='".get_settings('siteurl')."/wp-admin/post.php' method='get'>\n";
  519.     echo "<input type=\"hidden\" name=\"action\" value=\"deletecomment\" />\n";
  520.     echo "<input type=\"hidden\" name=\"p\" value=\"$p\" />\n";
  521.     echo "<input type=\"hidden\" name=\"comment\" value=\"$comment\" />\n";
  522.     echo "<input type=\"hidden\" name=\"noredir\" value=\"1\" />\n";
  523.     echo "<input type=\"submit\" value=\"" . __('Yes') . "\" />";
  524.     echo "  ";
  525.     echo "<input type=\"button\" value=\"" . __('No') . "\" onclick=\"self.location='". get_settings('siteurl') ."/wp-admin/edit.php?p=$p&c=1#comments';\" />\n";
  526.     echo "</form>\n";
  527.     echo "</div>\n";
  528.  
  529.     break;
  530.  
  531. case 'deletecomment':
  532.  
  533.     check_admin_referer();
  534.  
  535.     $comment = $_GET['comment'];
  536.     $p = $_GET['p'];
  537.     if (isset($_GET['noredir'])) {
  538.         $noredir = true;
  539.     } else {
  540.         $noredir = false;
  541.     }
  542.  
  543.     $postdata = get_post($p) or die(sprintf(__('Oops, no post with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  544.     $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'post.php'));
  545.  
  546.     if (!user_can_delete_post_comments($user_ID, $commentdata['comment_post_ID'])) {
  547.         die( __('You are not allowed to edit comments on this post.') );
  548.     }
  549.  
  550.     wp_set_comment_status($comment, "delete");
  551.     do_action('delete_comment', $comment);
  552.  
  553.     if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
  554.         header('Location: ' . $_SERVER['HTTP_REFERER']);
  555.     } else {
  556.         header('Location: '. get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
  557.     }
  558.  
  559.     break;
  560.  
  561. case 'unapprovecomment':
  562.  
  563.     require_once('./admin-header.php');
  564.  
  565.     check_admin_referer();
  566.  
  567.     $comment = $_GET['comment'];
  568.     $p = $_GET['p'];
  569.     if (isset($_GET['noredir'])) {
  570.         $noredir = true;
  571.     } else {
  572.         $noredir = false;
  573.     }
  574.  
  575.     $commentdata = get_commentdata($comment) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  576.  
  577.     if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
  578.         die( __('You are not allowed to edit comments on this post, so you cannot disapprove this comment.') );
  579.     }
  580.  
  581.     wp_set_comment_status($comment, "hold");
  582.  
  583.     if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
  584.         header('Location: ' . $_SERVER['HTTP_REFERER']);
  585.     } else {
  586.         header('Location: '. get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
  587.     }
  588.  
  589.     break;
  590.  
  591. case 'mailapprovecomment':
  592.  
  593.     $comment = (int) $_GET['comment'];
  594.  
  595.     $commentdata = get_commentdata($comment, 1, true) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  596.  
  597.     if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
  598.         die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
  599.     }
  600.  
  601.     if ('1' != $commentdata['comment_approved']) {
  602.         wp_set_comment_status($comment, 'approve');
  603.         if (true == get_option('comments_notify'))
  604.             wp_notify_postauthor($comment);
  605.     }
  606.  
  607.     header('Location: ' . get_option('siteurl') . '/wp-admin/moderation.php?approved=1');
  608.  
  609.     break;
  610.  
  611. case 'approvecomment':
  612.  
  613.     $comment = $_GET['comment'];
  614.     $p = $_GET['p'];
  615.     if (isset($_GET['noredir'])) {
  616.         $noredir = true;
  617.     } else {
  618.         $noredir = false;
  619.     }
  620.     $commentdata = get_commentdata($comment) or die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  621.  
  622.     if (!user_can_edit_post_comments($user_ID, $commentdata['comment_post_ID'])) {
  623.         die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
  624.     }
  625.  
  626.     wp_set_comment_status($comment, "approve");
  627.     if (get_settings("comments_notify") == true) {
  628.         wp_notify_postauthor($comment);
  629.     }
  630.  
  631.  
  632.     if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
  633.         header('Location: ' . $_SERVER['HTTP_REFERER']);
  634.     } else {
  635.         header('Location: '. get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
  636.     }
  637.  
  638.     break;
  639.  
  640. case 'editedcomment':
  641.  
  642.     $comment_ID = $_POST['comment_ID'];
  643.     $comment_post_ID = $_POST['comment_post_ID'];
  644.     $newcomment_author = $_POST['newcomment_author'];
  645.     $newcomment_author_email = $_POST['newcomment_author_email'];
  646.     $newcomment_author_url = $_POST['newcomment_author_url'];
  647.     $comment_status = $_POST['comment_status'];
  648.  
  649.     if (!user_can_edit_post_comments($user_ID, $comment_post_ID)) {
  650.         die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.') );
  651.     }
  652.  
  653.     if (user_can_edit_post_date($user_ID, $post_ID) && (!empty($_POST['edit_date']))) {
  654.         $aa = $_POST['aa'];
  655.         $mm = $_POST['mm'];
  656.         $jj = $_POST['jj'];
  657.         $hh = $_POST['hh'];
  658.         $mn = $_POST['mn'];
  659.         $ss = $_POST['ss'];
  660.         $jj = ($jj > 31) ? 31 : $jj;
  661.         $hh = ($hh > 23) ? $hh - 24 : $hh;
  662.         $mn = ($mn > 59) ? $mn - 60 : $mn;
  663.         $ss = ($ss > 59) ? $ss - 60 : $ss;
  664.         $datemodif = ", comment_date = '$aa-$mm-$jj $hh:$mn:$ss'";
  665.     } else {
  666.         $datemodif = '';
  667.     }
  668.     $content = apply_filters('comment_save_pre', $_POST['content']);
  669.  
  670.     $result = $wpdb->query("
  671.         UPDATE $wpdb->comments SET
  672.             comment_content = '$content',
  673.             comment_author = '$newcomment_author',
  674.             comment_author_email = '$newcomment_author_email',
  675.             comment_approved = '$comment_status',
  676.             comment_author_url = '$newcomment_author_url'".$datemodif."
  677.         WHERE comment_ID = $comment_ID"
  678.         );
  679.  
  680.     $referredby = $_POST['referredby'];
  681.     if (!empty($referredby)) {
  682.         header('Location: ' . $referredby);
  683.     } else {
  684.         header ("Location: edit.php?p=$comment_post_ID&c=1#comments");
  685.     }
  686.     do_action('edit_comment', $comment_ID);
  687.     break;
  688.  
  689. default:
  690.     $title = __('Create New Post');
  691.     require_once ('./admin-header.php');
  692. ?>
  693. <?php if ( isset($_GET['posted']) ) : ?>
  694. <div class="updated"><p><?php printf(__('Post saved. <a href="%s">View site »</a>'), get_bloginfo('home')); ?></p></div>
  695. <?php endif; ?>
  696. <?php
  697.     if (user_can_create_draft($user_ID)) {
  698.         $action = 'post';
  699.         get_currentuserinfo();
  700.         $drafts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'draft' AND post_author = $user_ID");
  701.         if ($drafts) {
  702.             ?>
  703.             <div class="wrap">
  704.             <p><strong><?php _e('Your Drafts:') ?></strong>
  705.             <?php
  706.             $i = 0;
  707.             foreach ($drafts as $draft) {
  708.                 if (0 != $i)
  709.                     echo ', ';
  710.                 $draft->post_title = stripslashes($draft->post_title);
  711.                 if ($draft->post_title == '')
  712.                     $draft->post_title = sprintf(__('Post # %s'), $draft->ID);
  713.                 echo "<a href='post.php?action=edit&post=$draft->ID' title='" . __('Edit this draft') . "'>$draft->post_title</a>";
  714.                 ++$i;
  715.                 }
  716.             ?>.</p>
  717.             </div>
  718.             <?php
  719.         }
  720.         //set defaults
  721.         $post_status = 'draft';
  722.         $comment_status = get_settings('default_comment_status');
  723.         $ping_status = get_settings('default_ping_status');
  724.         $post_pingback = get_settings('default_pingback_flag');
  725.         $default_post_cat = get_settings('default_category');
  726.  
  727.         $content = wp_specialchars($content);
  728.         $content = apply_filters('default_content', $content);
  729.         $edited_post_title = apply_filters('default_title', $edited_post_title);
  730.         $excerpt = apply_filters('default_excerpt', $excerpt);
  731.  
  732.         if (get_settings('advanced_edit')) {
  733.             include('edit-form-advanced.php');
  734.         } else {
  735.             include('edit-form.php');
  736.         }
  737. ?>
  738. <div class="wrap">
  739. <?php _e('<h3>WordPress bookmarklet</h3>
  740. <p>You can drag the following link to your links bar or add it to your bookmarks and when you "Press it" it will open up a popup window with information and a link to the site you’re currently browsing so you can make a quick post about it. Try it out:</p>') ?>
  741. <p>
  742.  
  743. <?php
  744. $bookmarklet_height= (get_settings('use_trackback')) ? 480 : 440;
  745.  
  746. if ($is_NS4 || $is_gecko) {
  747. ?>
  748. <a href="javascript:if(navigator.userAgent.indexOf('Safari') >= 0){Q=getSelection();}else{Q=document.selection?document.selection.createRange().text:document.getSelection();}void(window.open('<?php echo get_settings('siteurl') ?>/wp-admin/bookmarklet.php?text='+encodeURIComponent(Q)+'&popupurl='+encodeURIComponent(location.href)+'&popuptitle='+encodeURIComponent(document.title),'<?php _e('WordPress bookmarklet') ?>','scrollbars=yes,width=600,height=460,left=100,top=150,status=yes'));"><?php printf(__('Press It - %s'), wp_specialchars(get_settings('blogname'))); ?></a> 
  749. <?php
  750. } else if ($is_winIE) {
  751. ?>
  752. <a href="javascript:Q='';if(top.frames.length==0)Q=document.selection.createRange().text;void(btw=window.open('<?php echo get_settings('siteurl') ?>/wp-admin/bookmarklet.php?text='+encodeURIComponent(Q)+'<?php echo $bookmarklet_tbpb ?>&popupurl='+encodeURIComponent(location.href)+'&popuptitle='+encodeURIComponent(document.title),'bookmarklet','scrollbars=yes,width=600,height=<?php echo $bookmarklet_height ?>,left=100,top=150,status=yes'));btw.focus();"><?php printf(__('Press it - %s'), get_settings('blogname')); ?></a>
  753. <script type="text/javascript">
  754. <!--
  755. function oneclickbookmarklet(blah) {
  756. window.open ("profile.php?action=IErightclick", "oneclickbookmarklet", "width=500, height=450, location=0, menubar=0, resizable=0, scrollbars=1, status=1, titlebar=0, toolbar=0, screenX=120, left=120, screenY=120, top=120");
  757. }
  758. // -->
  759. </script>
  760. <br />
  761. <br />
  762. <?php _e('One-click bookmarklet:') ?><br />
  763. <a href="javascript:oneclickbookmarklet(0);"><?php _e('click here') ?></a> 
  764. <?php
  765. } else if ($is_opera) {
  766. ?>
  767. <a href="javascript:void(window.open('<?php echo get_settings('siteurl'); ?>/wp-admin/bookmarklet.php?popupurl='+escape(location.href)+'&popuptitle='+escape(document.title)+'<?php echo $bookmarklet_tbpb ?>','bookmarklet','scrollbars=yes,width=600,height=<?php echo $bookmarklet_height ?>,left=100,top=150,status=yes'));"><?php printf(__('Press it - %s'), get_settings('blogname')); ?></a> 
  768. <?php
  769. } else if ($is_macIE) {
  770. ?>
  771. <a href="javascript:Q='';if(top.frames.length==0);void(btw=window.open('<?php echo get_settings('siteurl'); ?>/wp-admin/bookmarklet.php?text='+escape(document.getSelection())+'&popupurl='+escape(location.href)+'&popuptitle='+escape(document.title)+'<?php echo $bookmarklet_tbpb ?>','bookmarklet','scrollbars=yes,width=600,height=<?php echo $bookmarklet_height ?>,left=100,top=150,status=yes'));btw.focus();"><?php printf(__('Press it - %s'), get_settings('blogname')); ?></a> 
  772. <?php
  773. }
  774. ?>
  775. </p>
  776. </div>
  777. <?php
  778. } else {
  779. ?>
  780. <div class="wrap">
  781. <p><?php printf(__('Since you’re a newcomer, you’ll have to wait for an admin to raise your level to 1, in order to be authorized to post.<br />
  782. You can also <a href="mailto:%s?subject=Promotion?">e-mail the admin</a> to ask for a promotion.<br />
  783. When you’re promoted, just reload this page and you’ll be able to blog. :)'), get_settings('admin_email')); ?>
  784. </p>
  785. </div>
  786. <?php
  787. }
  788.  
  789.     break;
  790. } // end switch
  791. /* </Edit> */
  792. include('admin-footer.php');
  793. ?>
  794.